package com.supermarket.user.controller;

import com.supermarket.common.core.web.controller.BaseController;
import com.supermarket.common.core.web.domain.AjaxResult;
import com.supermarket.common.core.web.page.TableDataInfo;
import com.supermarket.user.domain.User;
import com.supermarket.user.domain.dto.IntegralDto;
import com.supermarket.user.domain.dto.UserDto;
import com.supermarket.user.domain.vo.UserVo;
import com.supermarket.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    @Autowired
    private UserService userService;

    /**
     * 客户列表
     * @param userDto
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(UserDto userDto) {
        //分页
        startPage();
        List<UserVo> userVoList = userService.list(userDto);
        return getDataTable(userVoList);
    }
    //修改用户
    @PostMapping("/update")
    public AjaxResult update(@RequestBody @Validated User user) {
        return userService.updateUser(user);
    }
    /**
     * 给用户设置标签
     * @param tagIds
     * @param userIds
     * @return
     */
    @GetMapping("setTag/{tagIds}/{userIds}")
    public AjaxResult setTag(@PathVariable String tagIds, @PathVariable String userIds){
        return userService.setTag(tagIds,userIds);
    }

    /**
     * 修改积分
     * @param integralDto
     * @return
     */
    @PostMapping("updateIntegral")
    public AjaxResult updateIntegral(@RequestBody IntegralDto integralDto){
        return userService.updateIntegral(integralDto);
    }

    /**
     * 修改用户等级
     * @param userId
     * @param memberLevelId
     * @return
     */
    @GetMapping("updateLevel/{userId}/{memberLevelId}")
    public AjaxResult updateLevel(@PathVariable Long userId,@PathVariable Long memberLevelId){
        return userService.updateLevel(userId,memberLevelId);
    }

    /**
     * 批量冻结用户行为
     * @param userIds
     * @param typeIds
     * @return
     */
    @GetMapping("freeze/{userIds}/{typeIds}")
    public AjaxResult freeze(@PathVariable String userIds,@PathVariable String typeIds){
        return userService.freeze(userIds,typeIds);
    }

    /**
     * 批量添加优惠券
     * @param userIds
     * @param couponIds
     * @return
     */
    @GetMapping("addCoupon/{userIds}/{couponIds}")
    public AjaxResult addCoupon(@PathVariable String userIds,@PathVariable String couponIds){
        return userService.addCoupon(userIds,couponIds);
    }

    @GetMapping("userDetail/{userId}")
    public AjaxResult userDetail(@PathVariable Long userId){
        return userService.userDetail(userId);
    }

}
